#include "Chat.h"
#include "UserPortRS232.h"
#include "Input.h"
#include "StringTable.h"

#include <conio.h>
#include <cbm.h>
#include <stdio.h>

void enterChat(outDirections_t directions)
{
	static char r, c;
	bool dcdStart = readDCD();

	outputString(PLATFORM_ENCODING, directions, CHAT_ENTER);

	r = c = 0;
	while(c != CH_F7 && dcdStart == readDCD())
	{
		if(kbhit())
		{
			c = cgetc();
			if(directions & OD_MODEM) writeByteRS232(c);
			printf("%c", c);
		}

		if((r = sgetc()) != 0)
		{
			if(directions & OD_MODEM) writeByteRS232(r);
			printf("%c", r);
		}
	}

	outputString(PLATFORM_ENCODING, directions, CHAT_LEAVE);

	if(dcdStart != readDCD())
	{
		_connectState == CS_DISCONNECTED;
	}
}